<?php
namespace App\Controller;
use Think\Controller;
use App\Controller\BaseController;
class CrontabController extends BaseController {
    /**
     * 发货超过15天未收货的订单自动收货
     * @author chen
     */
    public function expireNoReceiveOrder(){
        $cur = time();
        $time = $cur - 15*24*3600;
        M('order')
            ->where([
                'order_status'=>['EQ',4],
                'order_sendtime'=>['ELT',$time],
            ])
            ->save([
                'order_status'=>5,
                'order_receivetime'=>$cur,
            ]);
    }

    /**
     * 清除半小时未付款的订单 为过期订单
     * @author chen
     *
     */
    public function expireNoPayOrder()
    {
        $time = time() - 30*60;
        M('order')
            ->where([
                'order_status'=>['EQ',1],
                'order_createtime'=>['LT',$time],
            ])
            ->save(['order_status'=>6]);
    }

    /**
     * 清除讲师正在直播时心跳超时的直播
     * @author chen
     *
     */
    public function expireLiveHeartbeatEnd()
    {
        $time = time();
        M('teacher_live')
            ->where([
                'teacher_live_status'=>['EQ',1],
                'teacher_live_heartbeat_endtime'=>['ELT',$time],
            ])
            ->save(['teacher_live_status'=>0]);
    }

    /**
     * 定时处理VIP过期的用户后更改用户身份为普通用户
     * @author chen
     *
     */
    public function expireUserVip()
    {
        //查询用户当前vip有效时间
        $time = time();
        M('user')
            ->where([
                'user_role'=>['EQ',2],
                'user_vip_valid_time'=>['ELT',$time],
            ])
            ->save([
                'user_role'=>1,
                'user_vip_valid_time'=>0,
            ]);
    }

    /**
     * 清除会议室权限时间过期的 将其权限清除
     * @author chen
     *
     */
    public function expireUserConferenceRole()
    {
        $time = time();
        M('user')
            ->where([
                'user_conference_valid_time'=>['ELT',$time],
            ])
            ->save(['user_conference_role'=>0]);
    }

    /**
     * 清除用户充值兑换金币和充值VIP时超时未付款的订单
     * @author chen
     *
     */
    public function expireUserMoney()
    {
        $time = time() - 30*60;
        M('user_money')
            ->where([
                'user_money_status'=>['EQ',1],
                'user_money_createtime'=>['ELT',$time],
            ])
            ->save(['user_money_status'=>2]);
    }

    /**
     * 讲师保存直播回放视频时，转码没那么快,定时获取回放url
     * @author chen
     *
     */
    public function getTeacherLivePlaybackUrl()
    {

    }

}